AbstractEventCommandHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 20
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A getUser 0 8 2
A getSchool 0 8 2
1
import { ISchoolRepository } from 'src/Domain/School/Repository/ISchoolRepository';
2
import { SchoolNotFoundException } from 'src/Domain/School/Exception/SchoolNotFoundException';
3
import { IUserRepository } from 'src/Domain/User/Repository/IUserRepository';
4
import { UserNotFoundException } from 'src/Domain/User/Exception/UserNotFoundException';
5
import { User } from 'src/Domain/User/User.entity';
6
import { School } from 'src/Domain/School/School.entity';
7
8
export abstract class AbstractEventCommandHandler {
9
  constructor(
10
    private readonly schoolRepository: ISchoolRepository,
11
    private readonly userRepository: IUserRepository
12
  ) {}
13
14
  protected async getUser(userId: string): Promise<User> {
15
    const user = await this.userRepository.findOneById(userId);
16
    if (!user) {
17
      throw new UserNotFoundException();
18
    }
19
20
    return user;
21
  }
22
23
  protected async getSchool(schoolId: string): Promise<School> {
24
    const school = await this.schoolRepository.findOneById(schoolId);
25
    if (!school) {
26
      throw new SchoolNotFoundException();
27
    }
28
29
    return school;
30
  }
31
}
32